<!-- 公共文件 start -->
@extends('admin.public.base')
<!-- 公共文件 end -->
<style>
    table th {
        min-width: 10px !important;
    }
    .layui-card-header {
        padding-top: 10px !important;
    }
</style>
@section('content')
    <div class="x-nav">
    <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="">销售管理</a>
        <a><cite>金额满赠</cite></a>
    </span>
        <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
           onclick="location.reload()" title="刷新">
            <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
        </a>
    </div>
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-body ">
                        <form class="layui-form layui-col-space5">
                            <div class="layui-inline layui-show-xs-block">
                                <input class="layui-input" autocomplete="off" placeholder="开始时间" name="start" id="start" value="{{request()->input('start')}}">
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <input class="layui-input" autocomplete="off" placeholder="截止时间" name="end" id="end" value="{{request()->input('end')}}">
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <button class="layui-btn" lay-submit="" lay-filter="sreach">
                                    <i class="layui-icon">&#xe615;搜索</i>
                                </button>
                            </div>
                        </form>
                    </div>
                    <div class="layui-card-header">
                        <button class="layui-btn" onclick="xadmin.open('添加金额满赠','/admin/sales/strategyAdd?type=1',1100,630)"><i class="layui-icon"></i>添加</button>
                    </div>
                    <div class="layui-card-body ">
                        <table class="layui-table layui-form" style="width: 100%">
                            <thead>
                            <tr>
                                <th>ID</th>
                                <th>名称</th>
                                <th>说明</th>
                                <th>生效时间</th>
                                <th>失效时间</th>
                                <th>状态</th>
                                <th>操作</th>
                            </thead>
                            <tbody>
                            @foreach($data as $item)
                                <tr>
                                    <td>
                                         {{$item['id']}}
                                    </td>
                                    <td>
                                        {{$item['type_str']}}
                                    </td>
                                    <td>
                                        {{$item['note']}}
                                    </td>
                                    <td>
                                        {{$item['start']}}
                                    </td>
                                    <td>
                                        {{$item['end']}}
                                    </td>
                                    <td>
                                        @if($item['status'] == '正常')
                                            <span style="color: #009688">{{$item['status']}}</span>
                                        @else
                                            <span style="color: #FF5722">{{$item['status']}}</span>
                                        @endif
                                    </td>
                                    <td class="td-manage" style="min-width: 140px">
                                        <button class="layui-btn layui-btn layui-btn-xs"  onclick="xadmin.open('编辑金额满赠','/admin/sales/strategyEdit?id={{$item['id']}}',1100,630)" ><i class="layui-icon">&#xe642;</i>编辑</button>
                                        <button class="layui-btn-danger layui-btn layui-btn-xs"  onclick="goods_del(this,{{$item['id']}})" href="javascript:;" ><i class="layui-icon">&#xe640;</i>删除</button>
                                    </td>
                                </tr>
                            @endforeach
                            </tbody>
                        </table>
                    </div>
                    <div class="layui-card-body ">
                        <div class="page">
                            {{ $data->links('admin/public/page') }}
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script>
        layui.use(['laydate', 'form'], function(){
            var form = layui.form,
                laydate = layui.laydate;

            //执行一个laydate实例
            laydate.render({
                elem: '#start', //指定元素
                type: 'datetime'
            });

            //执行一个laydate实例
            laydate.render({
                elem: '#end', //指定元素
                type: 'datetime'
            });
        });

        // 删除
        function goods_del(obj,id){
            layer.confirm('确认要删除吗？',function(index){
                //发异步删除数据
                $.ajax({
                    type: 'POST',
                    url: '/admin/sales/strategyDel',
                    data: {
                        id: id
                    },
                    dataType: 'json',
                    headers: {
                        'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
                    },
                    success: function (data) {
                        if (data.code == 1) {
                            $(obj).parents("tr").remove();
                            layer.msg('已删除',{icon:1,time:2000});
                        } else {
                            layer.alert(data.msg, {icon: 7, time: 2000, closeBtn: false, btn: []});
                        }
                    },
                    error: function (xhr, type) {
                        alert('Ajax error!')
                    }
                });
            });
        }
    </script>
@endsection
